package com.penghaisoft.microwms.product.web.controller.intowarehouse;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.penghaisoft.microwms.common.controller.BaseController;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.dto.TransResult;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.wms.model.ProBarcode;
import com.penghaisoft.microwms.product.service.IProBarcodeService;

/** 
* @ClassName: ProBarcodeController 
* @Description: 成品条码（登记生成）
* @author luoteng
* @date 2018年11月5日 上午10:53:13  
*/
@RestController
@RequestMapping(value = "/intowarehouse/checkIn/probarcode")
@Slf4j
public class ProBarcodeController extends BaseController {
	
		@Autowired
		private IProBarcodeService proBarcodeService;

	  /**
	   * 新增记录
	   * @param proBarcode
	   * @return
	   */
		@PostMapping("c")
		public TransResult create(ProBarcode proBarcode) {
			proBarcode.preInsert();
			Resp resp =  proBarcodeService.create(proBarcode);
			return fromResp(resp);
		}

	  /**
	   * 删除记录（逻辑删除active_flag=0)
	   * @param proBarcode
	   * @return
	   */
		@PostMapping("d")
		public TransResult delete(ProBarcode proBarcode) {
			proBarcode.preUpdate();
			Resp resp =  proBarcodeService.delete(proBarcode);
			return fromResp(resp);
		}

	  /**
	   * 查询列表
	   * @param pager
	   * @return
	   */
		@PostMapping("list")
		public TransResult list(@RequestParam(name = "page", defaultValue = "1") int page,
                            @RequestParam(name = "rows", defaultValue = "10") int rows,ProBarcode proBarcode) {
			Pager<ProBarcode> result = proBarcodeService.findListByCondition(page,rows,proBarcode);
			return success(result);
		}

	  /**
	   * 查询单条
	   * @param id
	   * @return
	   */
		@GetMapping("r/{id}")
		public TransResult queryById(@PathVariable String id) {
			ProBarcode  proBarcode = proBarcodeService.findById(id);
			return success(proBarcode);
		}

	  /**
	   * 修改记录
	   * @param proBarcode
	   * @return
	   */
		@PostMapping("u")
		public TransResult update(ProBarcode proBarcode) {
			proBarcode.preUpdate();
			Resp resp =  proBarcodeService.update(proBarcode);
	    	return fromResp(resp);
		}

}
